

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.io.Serializable;

public class LineObject extends ShapeObject implements Serializable{
	protected Point lineStart;
	protected Point lineEnd;
	public LineObject(Point startingMousePosition,Point endingMousePosition, Color color) {
		super(new Point(Math.min(startingMousePosition.x, endingMousePosition.x), 
				Math.min(startingMousePosition.y, endingMousePosition.y)), 
				new Point(Math.max(startingMousePosition.x, endingMousePosition.x), 
						Math.max(startingMousePosition.y, endingMousePosition.y)), color);
		this.lineStart = startingMousePosition;
		this.lineEnd = endingMousePosition;
	}

	protected DrawingCanvas canvas;

	
	public void drawShape(DrawingCanvas canvas){
    
	    Graphics iBGraphics = canvas.getImageBufferGraphics();
	    iBGraphics.setColor(this.color);
	    iBGraphics.drawLine(lineStart.x, lineStart.y, lineEnd.x, lineEnd.y);
	      
	    canvas.repaint();
	}

	public void moveObject(int x, int y){
		int dispX = x - this.startingMousePosition.x;
		int dispY = y - this.startingMousePosition.y;
		lineStart.x += dispX;
		lineEnd.x += dispX;
		lineStart.y += dispY;
		lineEnd.y += dispY;
		super.moveObject(x, y);
	}
	public void resizeStartObject(Point p){
		if(this.lineStart.x == this.startingMousePosition.x)
			this.lineStart.x = p.x;
		if(this.lineEnd.x == this.startingMousePosition.x)
			this.lineEnd.x = p.x;
		if(this.lineStart.y == this.startingMousePosition.y)
			this.lineStart.y = p.y;
		if(this.lineEnd.y == this.startingMousePosition.y)
			this.lineEnd.y = p.y;
		
		this.startingMousePosition = p;
	}
	public void resizeEndObject(Point p){
		if(this.lineStart.x == this.endingMousePosition.x)
			this.lineStart.x = p.x;
		if(this.lineEnd.x == this.endingMousePosition.x)
			this.lineEnd.x = p.x;
		if(this.lineStart.y == this.endingMousePosition.y)
			this.lineStart.y = p.y;
		if(this.lineEnd.y == this.endingMousePosition.y)
			this.lineEnd.y = p.y;
		
		this.endingMousePosition = p;
	}
	public boolean isResizeable() {
		return true;
	}
}
